layui.define(['table', 'form', 'laydate'], function(exports){
    var $ = layui.$,table = layui.table,form = layui.form, laydate = layui.laydate;

    laydate.render({
        elem: '#searchDate'
        , type: 'date'
        , range: false
        ,showBottom: false
        , trigger: 'click'
    });

    table.render({
        elem: '#LAY-table'
        ,url: layui.setter.webRoot + '/user/statistics/day/list.data'
        ,method: 'post'
        ,parseData: function (res) {
            return {
                "code": res.code,
                "msg": res.msg,
                "count": res.body.total,
                "data": res.body.data
            };
        }
        ,response: {statusCode: 200}
        ,cols: [[
            {field: 'dayDate', title: '统计时间'}
            ,{field: 'userId', title: '用户ID'}
            ,{field: 'userName', title: '用户名称'}
            ,{field: 'userPhone', title: '用户手机号'}
            ,{field: 'orderMoneyStr', title: '总分成金额'}
            ,{field: 'incomeCount', title: '收益次数'}
            ,{field: 'incomeMoneyStr', title: '收益金额'}
            ,{field: 'refundCount', title: '退款次数'}
            ,{field: 'refundMoneyStr', title: '退款金额'}
            ,{field: 'historyRefundCount', title: '历史订单退款次数'}
            ,{field: 'historyRefundMoneyStr', title: '历史订单退款金额'}
        ]]
        ,page: true
        ,limit: 30
        ,height: 'full'
        ,text: '对不起，加载出现异常！'
    });

    //监听搜索
    form.on('submit(LAY-search)', function(data){
        var field = data.field;
        //执行重载
        table.reload('LAY-table', {
            where: field
        });
    });

    var active = {
        toYear:function (){
            location.href = layui.setter.webRoot + '/user/statistics/index.html';
        }
        ,toMonth:function (){
            location.href = layui.setter.webRoot + '/user/statistics/month/index.html';
        }
    }

    $('.layui-btn.LAY-btn-fun').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    table.on('tool(LAY-table)', function (obj) {
        var type = obj.event;
        active[type] ? active[type].call(this, obj) : '';
    });

    exports('user_statistics_day_index', {})
});